package com.atguigu3.common_algorithm.exer3;

/**
 * @author lhl
 * 创建一个长为6的int型数组，要求数组元素的值都在1-30之间，且是随机赋值。同时，要求元素的值各不相同.
 * @date 2025/3/31 11:04
 */
public class ArrayExer03 {
    public static void main(String[] args) {
        //1.数组初始化
        int[] arr = new int[6];
        //2.数组的赋值
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int)(Math.random()*30)+1;
            boolean flag = false;
            while (true){
                for (int j = 0; j < i; j++) {
                    if (arr[i] == arr[j]){
                        flag = true;
                        break;
                    }
                }

                if (flag){
                    arr[i] = (int)(Math.random()*30)+1;
                    flag = false;
                    continue;
                }
                break;
            }
        }


        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }
}
